package ar.com.sgsvm.view.cliente;

import java.text.Collator;
import java.util.Comparator;

import ar.com.sgsvm.entity.Cliente;

public class ClienteComparator implements Comparator<Cliente> {

	private int mWhich;
	private int mAsc;

	public ClienteComparator(int which, int asc) {
		mWhich = which;
		mAsc = asc;
	}

	@Override
	public int compare(Cliente c1, Cliente c2) {
		
		Collator collator = Collator.getInstance();
		collator.setStrength(Collator.PRIMARY);
		switch (mWhich) {
		case 0: //idCliente
			Long id1 = c1.getIdCliente();
			Long id2 = c2.getIdCliente();
			return id1.compareTo(id2) * (mAsc);
		case 1: //apellido
			String a1 = c1.getApellido();
			String a2 = c2.getApellido();
			return collator.compare(a1, a2) * (mAsc);
		case 2: //nombre
			String n1 = c1.getNombre();
			String n2 = c2.getNombre();
			return collator.compare(n1, n2) * (mAsc);
		case 3: //direccion
			String d1 = c1.getDireccion();
			String d2 = c2.getDireccion();
			return collator.compare(d1, d2) * (mAsc);
		case 4: //localidad
			String l1 = c1.getLocalidad().getNombre();
			String l2 = c2.getLocalidad().getNombre();
			return collator.compare(l1, l2) * (mAsc);
		case 5: //telefono
			Long t1 = c1.getTelefono();
			Long t2 = c2.getTelefono();
			return t1.compareTo(t2) * (mAsc);
		}
		return 0;
	}

}
